package main.leetcode.primary.from001to100;

import java.util.HashMap;

public class ex1 {
    public static void main(String[] args) {
        System.out.println();
    }

    public int[] twoSum(int[] nums, int target) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; ++i) {
            map.put(nums[i], i);
        }
        for (int i = 0; i < nums.length; ++i) {
            int index = map.getOrDefault(target - nums[i], -1);
            if (index != -1 && index != i) {
                return new int[] {i, index};
            }
        }
        return new int[] {};
    }
}
